/*
 * Copyright 2005-2013 finalist.cn. All rights reserved.
 * Support: http://www.finalist.cn
 * License: http://www.finalist.cn/license
 */
package com.finalist.template.directive;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Component;

import com.finalist.util.DateUtil;

import freemarker.core.Environment;
import freemarker.template.TemplateDirectiveBody;
import freemarker.template.TemplateException;
import freemarker.template.TemplateModel;

/**
 * 模板指令 - 商品：时间
 * 
 * @author Finalist IT Group
 * @version 3.0
 */
@Component("productDatesDirective")
public class ProductDatesDirective extends BaseDirective {

	@SuppressWarnings({ "unchecked", "rawtypes" })
	public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException {
		List dates = getDates();
		setLocalVariable("dates", dates, env, body);
	}
	
	public List<String> getDates(){
		List<String> dates =  new ArrayList<String>(); 
		Date now = new Date();
		for(int i = 0 ; i< 12 ; i++){
			dates.add(DateUtil.getYear(DateUtil.addMonth(now, i))+"-"+DateUtil.getMonth(DateUtil.addMonth(now, i)));
		}
		return dates;
	}

}